fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {
    let mut result: [[i32; 3]; 3] = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
    for i in 0..3 {
        for j in 0..3 {
            let x = matrix[j][i];
            result[i][j] = x;
        }
    }
    return result;
}

fn pretty_print(matrix: &[[i32; 3]; 3]) {
    for i in 0..3 {
        let x = matrix[i];
        for j in 0..3 {
            print!("{} ", x[j])
        }
        println!()
    }
}

#[test]
fn test() {
    let mut demo = String::from("123456789");
    println!("{demo}");


    let digest = compute_digest("Hello");
    println!("digest: {digest:?}");


    let matrix = [
        [101, 102, 103], // <-- the comment makes rustfmt add a newline
        [201, 202, 203],
        [301, 302, 303],
    ];

    println!("matrix:");
    pretty_print(&matrix);

    let transposed = transpose(matrix);
    println!("transposed:");
    pretty_print(&transposed);
}

const DIGEST_SIZE: usize = 3;
const ZERO: Option<u8> = Some(42);

fn compute_digest(text: &str) -> [u8; DIGEST_SIZE] {
    let mut digest = [ZERO.unwrap_or(0); DIGEST_SIZE];
    for (idx, &b) in text.as_bytes().iter().enumerate() {
        digest[idx % DIGEST_SIZE] = digest[idx % DIGEST_SIZE].wrapping_add(b);
    }
    digest
}
